<?php

if(define(__FILE__,true)) {
	
	class Rebel_XTPL_Template {
		
		public static function display($xsl,$xml,$cache_ttl=60) {
			
			$_xsl = self::getXsl($xsl);
			$_xml = self::getXml($xml);
			
			if($err = Rebel_Error::instance()->get()) {
				throw new Exception($err['message'],$err['code']);
			}
			
			$p = new XSLTProcessor();
			$p->registerPHPFunctions();
			$p->importStylesheet($_xsl);
			
			return $p->transformToXml($_xml);
		}//:-

		
		private static function getXsl($xsl) {
			if(($xsl instanceof DOMDocument)) {
				
				return $xsl;
				
			} elseif ($xsl = Rebel_XTPL_Loader::load($xsl)) {
				
				return DOMDocument::load($xsl);
				
			} elseif (is_string($xsl)) {
				
				return DOMDocument::loadXML($xsl);
				
			}
			return null;
		}//:-
		
		private static function getXml($xml) {
			if(($xml instanceof DOMDocument)) {

				return $xml;
				
			} elseif ($xml = Rebel_XTPL_Loader::loadXml($xml)) {
				
				return DOMDocument::load($xml);
			
			} elseif (is_string($xml)) {
				
				return DOMDocument::loadXML($xml);
				
			}
		}//:-
		
	}///:-
	
}

?>